#pragma once

#include "event_loop.h"
#include "channel.h"

using ConnectionCB = std::function<void(int)>;

class Acceptor{
public:
    Acceptor(EventLoop* loop);
    ~Acceptor();

    void Listen();

    bool Init();
    void PipeFdInit();
    bool SocketBindListen(int port, int listen_num);
    void AcceptConnection();
    void SetCB(const ConnectionCB& cb){
        connectionCB_ = cb;
    }

public:
    static int SetNonBlocking(int fd);
    int GetListenFd(){
        return listenFd_;
    }

private:   
    EventLoop* loop_;
    int listenFd_;
    ChannelPtr listenChannel_;

    ConnectionCB connectionCB_;
};